package com.enjoyor.soa.traffic.server.tsms.dubbo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tsms.TaskExecuteRecordDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tsms.IDubboTaskExecuteRecordService;
import com.enjoyor.soa.traffic.core.tsms.domain.TaskExecuteRecord;
import com.enjoyor.soa.traffic.core.tsms.service.ITaskExecuteRecordService;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.helper.ResultHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@SuppressWarnings("rawtypes")
@Service(version = "1.0.0", timeout = 4000)
public class DubboTaskExecuteRecordService implements IDubboTaskExecuteRecordService {

    @Autowired
    private ITaskExecuteRecordService taskExecuteRecordService;

    @Override
    public ResultPojo getExecuteTaskRecordById(String recordId) {
    	TaskExecuteRecord executeRecord = taskExecuteRecordService.getExecuteTaskRecordById(recordId);
    	TaskExecuteRecordDto taskExecuteRecordDto = ReflectHelper.beanToBean(executeRecord, TaskExecuteRecordDto.class);
        return ResultHelper.getResult(taskExecuteRecordDto);
    }
    @Override
	public ResultPojo getExecuteTaskRecordList(String recordId, String executeTaskId, String taskId, String recordTypeId,
			String isWarn, String beginTime, String endTime) {
    	List<TaskExecuteRecord> executeRecordList = taskExecuteRecordService.getExecuteTaskRecordList(recordId, 
    			executeTaskId, taskId, recordTypeId, isWarn, beginTime, endTime);
    	List<TaskExecuteRecordDto> executeRecordDtoList = ReflectHelper.listToList(executeRecordList, 
    			TaskExecuteRecordDto.class);
		return ResultHelper.getResult(executeRecordDtoList);
	}
    @Override
	public ResultPojo getExecuteTaskRecordPage(Page page, String recordId, String executeTaskId, String taskId, 
			String recordTypeId, String isWarn, String beginTime, String endTime) {
		page = taskExecuteRecordService.getExecuteTaskRecordPage(page, recordId, executeTaskId, taskId, recordTypeId, 
				isWarn, beginTime, endTime);
		return ResultHelper.getResult(page);
	}
    @Override
    public ResultPojo insertRecord(TaskExecuteRecordDto taskExecuteRecordDto, String personName) {
    	TaskExecuteRecord executeRecord = ReflectHelper.beanToBean(taskExecuteRecordDto, TaskExecuteRecord.class);
    	String recordId = taskExecuteRecordService.insertRecord(executeRecord, personName);
		return ResultHelper.getResult(recordId);
    }
}
